<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
  <style type="text/css">
    body, html {
      width: 100%;
      height: 100%;
      margin: 0;
      font-family: "微软雅黑";
      font-size: 14px;
    }

    #allmap {
      width: 100%;
      height: 500px;
    }
  </style>
  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <!--<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=G3DHa70sej3ND9kT4xrCEyWKGy7BfrgB&services=&t=20180102152545"></script>-->

  <script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=G3DHa70sej3ND9kT4xrCEyWKGy7BfrgB&services=&t=20180102152545"></script>



  <title>逆地址解析</title>
</head>
<body>
<div id="allmap"></div>
<p>点击地图展示详细地址</p>
</body>
</html>
<script type="text/javascript">
  function getpostion(){
    //var url = "http://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&callback=renderReverse&location="+latlon+"&output=json&pois=0";
    var url = "http://www.gc.com/H5/address/index.php";

    $.ajax({
      type      : "GET",
      dataType  : "json",
      url       : url,
      success   : function(json){
//          $("#baidu_geo").html(json.address);
        var x = json.x;
        var y = json.y;

        // 百度地图API功能
        var map = new BMap.Map("allmap");
        var point = new BMap.Point(x, y);
        var geoc = new BMap.Geocoder();

        var marker = new BMap.Marker(point);        // 创建标注

        map.enableScrollWheelZoom(true);
        map.addOverlay(marker);                     // 将标注添加到地图中
        marker.enableDragging();  //设置点可以拖拽
        map.centerAndZoom(point, 12);
        var pt = point;
        geoc.getLocation(pt, function(rs){
          var addComp = rs.addressComponents;
          alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
        });


//        map.addEventListener("click", function(e){
//          var pt = e.point;
//          geoc.getLocation(pt, function(rs){
//            var addComp = rs.addressComponents;
//            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
//          });
//        });

      },
      error     : function(XMLHttpRequest, textStatus, errorThrown){
        $("#baidu_geo").html(errorThrown+"地址位置获取失败");
      }
    });
  }

  getpostion();

</script>
